require 'test/unit'
require_relative 'Factory'

class TCSingleton < Test::Unit::TestCase
    def testSingetonNew
      assert_raises (NoMethodError) do
        ProductFactory.new
      end
    end

  def testSingletonReferences
    list = []
    base_ref = ProductFactory.instance
    list.push base_ref
    list.push MockClass.new.singleton
    100.times do
      list.push MockClass.new.singleton
    end
    list.each { |ref|
    assert_same ref,base_ref
    assert_instance_of ProductFactory,base_ref
    assert_kind_of Singleton,base_ref
    assert_same base_ref,ref
    }
  end

  class MockClass
    attr_reader :singleton
    def initialize
    @singleton = ProductFactory.instance
    end
  end
end